import logging
from logging.handlers import TimedRotatingFileHandler
from datetime import datetime

from map_backend.settings import LOGS_DIR

# 日常信息日志
day=datetime.now().strftime('%Y-%m-%d')
dayLogger = logging.getLogger('InfoLogger')
dayLogger.setLevel(logging.INFO )

dayHandler = TimedRotatingFileHandler('{0}/{1}.log'.format(LOGS_DIR,day), when='midnight', interval=1, backupCount=7,encoding='utf-8')
dayFormatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
dayHandler.setFormatter(dayFormatter)
dayLogger.addHandler(dayHandler)


# 错误信息日志
errorLogger = logging.getLogger('ErrorLogger')
errorLogger.setLevel(logging.ERROR)
errorHandler = logging.FileHandler('{0}/error.log'.format(LOGS_DIR), encoding='utf-8')
errorFormatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
errorHandler.setFormatter(errorFormatter)
errorLogger.addHandler(errorHandler)